package com.xoa.service.inv.impl;

import com.xoa.dao.crm.CustomerMapper;
import com.xoa.dao.inv.*;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.inv.*;
import com.xoa.model.users.Users;
import com.xoa.service.inv.OmShipmentService;
import com.xoa.util.*;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;


@Service
public class SalesShipmentServiceImpl implements OmShipmentService {
    @Resource
    private UsersMapper usersMapper;
    @Resource
    private OmShipmentMapper omShipmentMapper;
    @Resource
    private PoCommodityEnterMapper poCommodityEnterMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private InvWarehouseMapper invWarehouseMapper;
    @Resource
    private ProductTypeMapper productTypeMapper;
    @Autowired
    private OmReturnMapper omReturnMapper;
    @Autowired
    private CusPaymentMapper cusPaymentMapper;
    @Autowired
    private CusReceiptMapper cusReceiptMapper;
    /**
     * 查询所有
     */
    @Override
    public List<OmShipment> selectAll(Map<String, Object> map) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List<OmShipment> omShipments = omShipmentMapper.selectAll(map);
        List<OmShipment> news = new ArrayList<>();
        if(omShipments!=null && omShipments.size()>0){
            for (OmShipment omShipment : omShipments
            ) {
                omShipment.setShipmentDateStr(format.format(omShipment.getShipmentDate()));
                Users userByuid = usersMapper.findUserByuid(Integer.valueOf(omShipment.getUserId()));
                if(userByuid!=null){
                    omShipment.setShipper(userByuid.getUserName());
                }
                omShipment.setCustomerName(customerMapper.selectByPrimaryKey(omShipment.getCustomerId()).getCustomerName());
                omShipment.setWarehouseName(invWarehouseMapper.selectByPrimaryKey(omShipment.getWarehouseId()).getWarehouseName());
                //商品大类名称
                if (omShipment.getEnterId() != null) {
                    PoCommodityEnter poCommodityEnter = poCommodityEnterMapper.selectByPrimaryKey(omShipment.getEnterId());
                    ProductType productType = productTypeMapper.selectByPrimaryKey(Integer.valueOf(poCommodityEnter.getProductType()));
                    if (productType != null) {
                        omShipment.setProductType(productType.getProductTypeName());
                    }
                }

                news.add(omShipment);
            }
        }
        return news;
    }

    /**
     * 查询所有欠款用户
     */
    @Override
    public List<OmShipment> selectCustomerId(String customerName) {
        OmShipment os = new OmShipment();
        os.setCustomerName(customerName);
        List<OmShipment> omShipments = omShipmentMapper.selectCustomerId(os);
        if (customerName == null || customerName == "") {
            for (OmShipment omShipment : omShipments
            ) {
                omShipment.setCustomerName(customerMapper.selectByPrimaryKey(omShipment.getCustomerId()).getCustomerName());
            }
        }
        if (omShipments != null) {
            return omShipments;
        } else {
            return null;
        }

    }

    /**
     * 数据回显接口
     */
    @Override
    public OmShipment selectByPrimaryKey(Integer shipmentId) {
        OmShipment omShipment = omShipmentMapper.selectByPrimaryKey(shipmentId);
        omShipment.setShipper(usersMapper.findUserByuid(Integer.parseInt(omShipment.getUserId())).getUserName());
        omShipment.setCustomerName(customerMapper.selectByPrimaryKey(omShipment.getCustomerId()).getCustomerName());
        omShipment.setWarehouseName(invWarehouseMapper.selectByPrimaryKey(omShipment.getWarehouseId()).getWarehouseName());
        return omShipment;
    }

    /**
     * 根据主键id进行删除(逻辑删除)
     */
    @Override
    public int deleteByPrimaryKey(Integer shipmentId) {
        return omShipmentMapper.deleteByPrimaryKey(shipmentId);
    }

    /**
     * 添加出货数据
     */
    @Override
    public int insertSales(OmShipment omShipment, Map<String, Object> maps) {
        //获取登录用户
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
        //  omShipment.setEnterId(poCommodityEnterMapper.selectEnterId(maps));
        Map<String, Object> map = new HashMap<>();
        map.put("enterId", omShipment.getEnterId());
        map.put("num", omShipment.getShipmentNum());
        map.put("way", null);
        poCommodityEnterMapper.updateByEnterId(map);
        omShipment.setUserId(String.valueOf(users.getUid()));
        Date date = new Date();//当前日期---生成单据号的主要因素
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String timeStr = format.format(date);
        String stt = "NO";//固定前缀
        int newNumber = 00001;//自增编号
        String documentNo = "";
        if (omShipment != null) {
            Map<String, Object> mapa = new HashMap<>();
            mapa.put("obj", new OmShipment());
            List<OmShipment> list = omShipmentMapper.selectAll(mapa);
            if (list.size() > 0 && list != null) {
                if (list.get(0).getDocumentNo() != null && !list.get(0).getDocumentNo().isEmpty()) {
                    String str = list.get(0).getDocumentNo().substring(10);
                    int newNo = Integer.parseInt(str) + 1;
                    String dtr = String.format("%05d", newNo);
                    documentNo = stt + timeStr + dtr;
                }
                omShipment.setDocumentNo(documentNo);
            } else {
                String dtr = String.format("%05d", newNumber);
                documentNo = stt + timeStr + dtr;
                omShipment.setDocumentNo(documentNo);
            }

        }
        return omShipmentMapper.insert(omShipment);
    }

    /**
     * 更新数据(根据产品id)
     */
    @Override
    public int updateByPrimaryKeySelective(OmShipment omShipment, String productType, String enterName, String enterSpecs, String enterCode) {
        ProductType product = new ProductType();
        ProductType type = productTypeMapper.selectProductTypeByName(productType);
        /*if (type.getProductTypeId() != 0) {
            omShipment.setEnterId(type.getProductTypeId());
        }*/
        return omShipmentMapper.updateByPrimaryKeySelective(omShipment);
    }

    /**
     * 出货信息表导出功能
     */
    @Override
    public ToJson<OmShipment> ExportOmShipment(HttpServletRequest request, HttpServletResponse response, OmShipment omShipment, String beginDate, String isExport) {
        ToJson<OmShipment> json = new ToJson<OmShipment>();
        try {
            Map<String, Object> maps = new HashMap<>();
            maps.put("obj", new OmShipment());
            List<OmShipment> omShipmentList = omShipmentMapper.selectAll(maps);
            List<OmShipment> omShipments = new ArrayList<>();
            for (OmShipment omShipment1 : omShipmentList) {
                if (omShipment1.getShipmentDate() != null) {
                    omShipment1.setShipmentDateStr(DateFormat.getStrDate(omShipment1.getShipmentDate()));
                    omShipment1.setShipper(usersMapper.findUserByuid(Integer.parseInt(omShipment1.getUserId())).getUserName());
                    omShipment1.setCustomerName(customerMapper.selectByPrimaryKey(omShipment1.getCustomerId()).getCustomerName());
                    omShipment1.setWarehouseName(invWarehouseMapper.selectByPrimaryKey(omShipment1.getWarehouseId()).getWarehouseName());
                }
                omShipments.add(omShipment1);
            }
            //条件判断[后端拼接条件进行判断]
            if ("yes".equals(isExport)) {
                // 设置Excel表头标题
                HSSFWorkbook workbook1 = ExcelUtil.makeExcelHead("销售出货表", 13);
                // 设置Excel表的字段名
                String[] secondTitles = {"商品大类", "商品名称", "商品规格", "商品编码", "出货日期", "出货数量", "出货单价", "合计", "已付金额", "欠款金额", "客户", "出货人", "仓库", "备注"};
                HSSFWorkbook workbook2 = ExcelUtil.makeSecondHead(workbook1, secondTitles);
                // 字段名对应的实体类属性名称
                String[] beanProperty = {"productType", "enterName", "enterSpecs", "enterCode", "shipmentDateStr", "shipmentNum", "shipmentPrice", "shipmentTotal", "shipmentPaid", "shipmentArrears", "customerName", "shipper", "warehouseName", "shipmentRemark"};
                HSSFWorkbook workbook = ExcelUtil.exportExcelData(workbook2, omShipmentList, beanProperty);
                ServletOutputStream out = response.getOutputStream();
                // 设置Excel表的导出名称
                String filename = "销售出货表.xls";
                filename = FileUtils.encodeDownloadFilename(filename, request.getHeader("user-agent"));
                response.setContentType("application/vnd.ms-excel");
                response.setHeader("content-disposition", "attachment;filename=" + filename);
                workbook.write(out);
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("err");
            json.setFlag(1);
        }
        return json;
    }

    //查询所有出货人
    @Override
    public ToJson<OmShipment> selectUsers() {
        ToJson<OmShipment> json = new ToJson<OmShipment>();
        List<OmShipment> omShipments = omShipmentMapper.selectUsers();
        for (OmShipment omShipment : omShipments) {
            omShipment.setShipper(usersMapper.findUserByuid(Integer.parseInt(omShipment.getUserId())).getUserName());
        }
        json.setMsg("ok");
        json.setFlag(0);
        json.setObj(omShipments);
        return json;
    }
    @Override
    public ToJson<OmShipment> shipCount(HttpServletRequest request, String year, String warehouseId) {
        if (StringUtils.checkNull(year)){
           year="2020";
        }
        ToJson<OmShipment> toJson=new ToJson<>();
        try {
            Map<String ,Object> map=new HashMap<>();
            if (!StringUtils.checkNull(warehouseId)){
                map.put("warehouseId",warehouseId);
            }
            Calendar calendar = Calendar.getInstance();
            int years = calendar.get(Calendar.YEAR);
            if (years<=Integer.parseInt(year)){
                map.put("shipmentDate",years);
            }else {
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy");
                Date date=simpleDateFormat.parse(year);
                map.put("shipmentDate",date);
            }
            int month = calendar.get(Calendar.MONTH) + 1;
            List<OmShipmentExample> omShipmentExamples = omShipmentMapper.selectShipCountByYear(map);
            List<OmShipmentExample> omShipmentExamples1 = omShipmentMapper.selectReturnCountByYear(map);
            List<OmShipmentExample> list=new ArrayList<>();
            for (int i=1;i<=12;i++){
                int s=0;
                int e=0;
                OmShipmentExample omShipmentExample4=new OmShipmentExample();
                for (OmShipmentExample omShipmentExample: omShipmentExamples){
                    if ((i+"").equals(omShipmentExample.getShipMonth())){
                        omShipmentExample4.setSaleShipPrice(Integer.parseInt(omShipmentExample.getSumShipMent()));
                        s++;
                    }
                }
                for (OmShipmentExample omShipmentExample1: omShipmentExamples1){
                    if ((i+"").equals(omShipmentExample1.getReturnMonth())){
                           omShipmentExample4.setSaleReturnPrice(Integer.parseInt(omShipmentExample1.getSumReturnMent()));
                           e++;
                    }
               }
               if (e==0){
                   omShipmentExample4.setSaleReturnPrice(0);
               }
               if (s==0){
                   omShipmentExample4.setSaleShipPrice(0);
               }
               omShipmentExample4.setReturnMonth(i+"");
               omShipmentExample4.setRealPrice(omShipmentExample4.getSaleReturnPrice()+omShipmentExample4.getSaleShipPrice());
               list.add(omShipmentExample4);
            }
            toJson.setObject(list);
            toJson.setFlag(1);
            toJson.setMsg("ok");
        }catch (Exception e){
          e.printStackTrace();
            toJson.setFlag(0);
            toJson.setMsg("error");
        }
        return toJson;
    }

    public ToJson<OmShipment> shipDayCount(HttpServletRequest request, String year, String warehouseId,String month) {
        if (StringUtils.checkNull(year)){
            year="2020";
        }
        if (StringUtils.checkNull(month)){
            month="1";
        }
        ToJson<OmShipment> toJson=new ToJson<>();
        try {
            Map<String ,Object> map=new HashMap<>();
            if (!StringUtils.checkNull(warehouseId)){
                map.put("warehouseId",warehouseId);
            }
            Calendar calendar = Calendar.getInstance();
            int years = calendar.get(Calendar.YEAR);
            if (years<=Integer.parseInt(year)){
                map.put("shipmentDate",years);
            }else {
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy");
                Date date=simpleDateFormat.parse(year);
                map.put("shipmentDate",date);
            }
            map.put("month",month);
          // int month = calendar.get(Calendar.MONTH) + 1;

            List<OmShipmentExample> omShipmentExamples = omShipmentMapper.selectShipCountByYear(map);
            List<OmShipmentExample> omShipmentExamples1 = omShipmentMapper.selectReturnCountByYear(map);
            List<OmShipmentExample> list=new ArrayList<>();
            Calendar a = Calendar.getInstance();
            a.set(Calendar.YEAR, Integer.parseInt(year));
            a.set(Calendar.MONTH, Integer.parseInt(month) - 1);
            a.set(Calendar.DATE, 1);
            a.roll(Calendar.DATE, -1);
            int maxDate = a.get(Calendar.DATE);
            int count=maxDate;
            for (int i=1;i<=count;i++){
                int s=0;
                int e=0;
                OmShipmentExample omShipmentExample4=new OmShipmentExample();
                for (OmShipmentExample omShipmentExample: omShipmentExamples){
                    if ((i+"").equals(omShipmentExample.getShipMonth())){
                        omShipmentExample4.setSaleShipPrice(Integer.parseInt(omShipmentExample.getSumShipMent()));
                        s++;
                    }
                }
                for (OmShipmentExample omShipmentExample1: omShipmentExamples1){
                    if ((i+"").equals(omShipmentExample1.getReturnMonth())){
                        omShipmentExample4.setSaleReturnPrice(Integer.parseInt(omShipmentExample1.getSumReturnMent()));
                        e++;
                    }
                }
                if (e==0){
                    omShipmentExample4.setSaleReturnPrice(0);
                }
                if (s==0){
                    omShipmentExample4.setSaleShipPrice(0);
                }
                omShipmentExample4.setReturnMonth(i+"");
                omShipmentExample4.setRealPrice(omShipmentExample4.getSaleReturnPrice()+omShipmentExample4.getSaleShipPrice());
                list.add(omShipmentExample4);
            }
            toJson.setObject(list);
            toJson.setFlag(1);
            toJson.setMsg("ok");
        }catch (Exception e){
            e.printStackTrace();
            toJson.setFlag(0);
            toJson.setMsg("error");
        }
        return toJson;
    }

    @Override
    public ToJson<OmShipment> shipEmployeeCount(HttpServletRequest request, String year, String warehouseId,String month,String flag) {
        if (StringUtils.checkNull(year)){
            year="2020";
        }
        if (StringUtils.checkNull(month)&&StringUtils.checkNull(flag)){
            month="1";
        }
        ToJson<OmShipment> toJson=new ToJson<>();
        try {
            Map<String ,Object> map=new HashMap<>();
            if (!StringUtils.checkNull(warehouseId)){
                map.put("warehouseId",warehouseId);
            }
            Calendar calendar = Calendar.getInstance();
            int years = calendar.get(Calendar.YEAR);
            if (years<=Integer.parseInt(year)){
                map.put("shipmentDate",years);
            }else {
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy");
                Date date=simpleDateFormat.parse(year);
                map.put("shipmentDate",date);

            }
            map.put("month",month);
         //   int month = calendar.get(Calendar.MONTH) + 1;

            List<OmShipmentExample> omShipmentExamples = omShipmentMapper.selectShipCountByEmployee(map);
            OmShipmentExample omShipmentExample2=new OmShipmentExample();
            for (OmShipmentExample omShipmentExample:omShipmentExamples){
                if (!StringUtils.checkNull(omShipmentExample.getUserId())){
                    omShipmentExample.setUserName(usersMapper.getUsernameById(omShipmentExample.getUserId()));
                }
                if (!StringUtils.checkNull(omShipmentExample.getSumShipMent()+"")&&!"null".equals(omShipmentExample.getSumShipMent()+"")){
                    if (StringUtils.checkNull(omShipmentExample2.getSaleShipPrice()+"")||"null".equals(omShipmentExample2.getSaleShipPrice()+"")){
                        omShipmentExample2.setSaleShipPrice(0);
                    }

                    omShipmentExample2.setSaleShipPrice(omShipmentExample2.getSaleShipPrice()+Integer.parseInt(omShipmentExample.getSumShipMent()));
                }
            }
            for (OmShipmentExample omShipmentExample:omShipmentExamples){
                if(omShipmentExample2.getSaleShipPrice()==0){
                    omShipmentExample.setSaleShipper("100%");
                }else{
                    omShipmentExample.setSaleShipper(accuracy(Integer.parseInt(omShipmentExample.getSumShipMent()), omShipmentExample2.getSaleShipPrice(), 1));
                }
            }
            toJson.setObject(omShipmentExamples);
            toJson.setFlag(1);
            toJson.setMsg("ok");
        }catch (Exception e){
            e.printStackTrace();
            toJson.setFlag(0);
            toJson.setMsg("error");
        }
        return toJson;
    }
    @Override
    public ToJson<OmShipment> shipCustomerCount(HttpServletRequest request, String year, String warehouseId,String month,String flag) {
        if (StringUtils.checkNull(year)){
            year="2020";
        }
        if (StringUtils.checkNull(month)&&StringUtils.checkNull(flag)){
            month="1";
        }
        ToJson<OmShipment> toJson=new ToJson<>();
        try {
            Map<String ,Object> map=new HashMap<>();
            if (!StringUtils.checkNull(warehouseId)){
                map.put("warehouseId",warehouseId);
            }
            Calendar calendar = Calendar.getInstance();
            int years = calendar.get(Calendar.YEAR);
            if (years<=Integer.parseInt(year)){
                map.put("shipmentDate",years);
            }else {
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy");
                Date date=simpleDateFormat.parse(year);
                map.put("shipmentDate",date);

            }
            map.put("month",month);
            //   int month = calendar.get(Calendar.MONTH) + 1;

            List<OmShipmentExample> omShipmentExamples = omShipmentMapper.selectShipCountByCustomer(map);
            OmShipmentExample omShipmentExample2=new OmShipmentExample();
            for (OmShipmentExample omShipmentExample:omShipmentExamples){
                if (!StringUtils.checkNull(omShipmentExample.getCustomerId())){
                    OmShipment omShipments = omShipmentMapper.selectCustomerById(omShipmentExample.getCustomerId());
                    omShipmentExample.setUserName(omShipments.getCustomerName());
                }
                if (!StringUtils.checkNull(omShipmentExample.getSumShipMent()+"")&&!"null".equals(omShipmentExample.getSumShipMent()+"")){
                    if (StringUtils.checkNull(omShipmentExample2.getSaleShipPrice()+"")||"null".equals(omShipmentExample2.getSaleShipPrice()+"")){
                        omShipmentExample2.setSaleShipPrice(0);
                    }
                    omShipmentExample2.setSaleShipPrice(omShipmentExample2.getSaleShipPrice()+Integer.parseInt(omShipmentExample.getSumShipMent()));
                }
            }
            for (OmShipmentExample omShipmentExample:omShipmentExamples){
                omShipmentExample.setSaleShipper(accuracy(Integer.parseInt(omShipmentExample.getSumShipMent()), omShipmentExample2.getSaleShipPrice(), 1));
            }
            toJson.setObject(omShipmentExamples);
            toJson.setFlag(1);
            toJson.setMsg("ok");
        }catch (Exception e){
            e.printStackTrace();
            toJson.setFlag(0);
            toJson.setMsg("error");
        }
        return toJson;
    }

    //其他收支
    @Override
    public ToJson<OmShipment> shipOtherCount(HttpServletRequest request, String year, String warehouseId, String month, String flag, String day) {
        ToJson/*
        if (StringUtils.checkNull(year)){
            year="2020";
        }*/
                <OmShipment> toJson=new ToJson<>();
        try {
            Map<String ,Object> map=new HashMap<>();
            if (!StringUtils.checkNull(warehouseId)){
                map.put("warehouseId",warehouseId);
            }
            if (!StringUtils.checkNull(year)){
                map.put("year" ,year);
            }
            if (!StringUtils.checkNull(month)){
                map.put("month",month.split("-")[1]);
                map.put("year",month.split("-")[0]);
            }
            List<Double> map1=new ArrayList<>();
            OmShipmentExample omShipmentExample2=new OmShipmentExample();
            List<OmShipmentExample> list = omShipmentMapper.selectShipCount(map);
            //利润总计
            Double realPrice=0.00;

            //销售总计
            Double saleShipPrice=0.00;

            //销售退货总计
            Double saleReturnPrice=0.00;

            for(OmShipmentExample omShipment:list){
                if ("null".equals(omShipment.getSaleShipPrice()+"")){
                    omShipment.setSaleShipPrice(0);
                }
                if ("null".equals(omShipment.getRealPrice()+"")){
                    omShipment.setRealPrice(0);
                }
                realPrice+=omShipment.getRealPrice();
                saleShipPrice+=omShipment.getSaleShipPrice();
            }
            //退货总计
            List<OmShipmentExample> list1 = omShipmentMapper.selectReturnCount(map);
            List<OmShipmentExample> lists=new ArrayList<>();
            for (OmShipmentExample omShipmentExample:list1){
               if ("null".equals(omShipmentExample.getSaleReturnPrice()+"")){
                   omShipmentExample.setSaleReturnPrice(0);
               }
                if ("null".equals(omShipmentExample.getRealPrice2()+"")){
                    omShipmentExample.setRealPrice2(0);
                }
                saleReturnPrice+=omShipmentExample.getSaleReturnPrice();
                realPrice-=omShipmentExample.getRealPrice2();
            }
            //采购进货
            Double enterPrice = poCommodityEnterMapper.selectEnterTotal(map);
            if ("null".equals(enterPrice+"")){
                enterPrice=0.00;
            }
            omShipmentExample2.setEnterPrice(enterPrice);
            //采购退货
            Double outPrice = poCommodityEnterMapper.selectOutTotal(map);

            if ("null".equals(outPrice+"")){
                outPrice=0.00;
            }
            omShipmentExample2.setOutPrice(outPrice);
            //经营支出
            Double paymentPrice = cusPaymentMapper.selectCusPaymentCount(map);
            if ("null".equals(paymentPrice+"")){
                paymentPrice=0.00;
            }
            omShipmentExample2.setPaymentPrice(paymentPrice);
            //经营收入
            Double receiptPrice = cusPaymentMapper.selectCusReceiptCount(map);
            if ("null".equals(receiptPrice+"")){
                receiptPrice=0.00;
            }
            //经营利润
            Double jingyinglirun=receiptPrice-paymentPrice;
            omShipmentExample2.setReceiptPrice(receiptPrice);
            //累积收入
            Double totalEnterPrice=receiptPrice+saleShipPrice+outPrice;
            omShipmentExample2.setTotalEnterPrice(totalEnterPrice);
            //累积支出
            Double totalOutPrice=paymentPrice+enterPrice+saleReturnPrice;
            omShipmentExample2.setTotalOutPrice(totalOutPrice);
            Double endPrice=totalEnterPrice-totalOutPrice;
            omShipmentExample2.setEndPrice(endPrice);
            omShipmentExample2.setRealPrice3(realPrice);
            omShipmentExample2.setSaleShipPrice2(saleShipPrice);
            omShipmentExample2.setSaleReturnPrice2(saleReturnPrice);
            omShipmentExample2.setJingyinglirun(jingyinglirun);
            lists.add(omShipmentExample2);
            toJson.setObject(lists);
            toJson.setFlag(1);
            toJson.setMsg("ok");
        }catch (Exception e){
            e.printStackTrace();
            toJson.setFlag(0);
            toJson.setMsg("error");
        }
        return toJson;
    }


    public static String accuracy(double num, double total, int scale){
        DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
        //可以设置精确几位小数
        df.setMaximumFractionDigits(scale);
        //模式 例如四舍五入
        df.setRoundingMode(RoundingMode.HALF_UP);
        double accuracy_num = num / total * 100;
        return df.format(accuracy_num)+"%";
    }

}
